package cn.mccraft.uide.api.util.i18n;

import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.commons.lang3.Validate;

public class SimpleI18n implements I18n {
	
	private final ResourceBundle resourceBundle;
	
	public SimpleI18n(String baseName, Locale locale) {
		resourceBundle = ResourceBundle.getBundle(baseName, locale, new UTF8Control());
	}
	
	public SimpleI18n(String baseName, Locale locale, ClassLoader classLoader) {
		resourceBundle = ResourceBundle.getBundle(baseName, locale, classLoader, new UTF8Control());
	}

	@Override
	public String localize(String key) {
		Validate.notEmpty(key);
		return resourceBundle.containsKey(key) ? resourceBundle.getString(key) : key;
	}

	@Override
	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}
}
